// common/components/selectPopup/selectPopup.js
import {
  keyArrLength
} from '../../../utils/util.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    visible: {
      type: Boolean,
      value: false
    },
    list: {
      type: Object,
      value: {},
      // value: {
      //   "key": [{
      //     name: 'key1',
      //     value: 1
      //   }, {
      //     name: 'key2',
      //     value: 1
      //   }, {
      //     name: 'key3',
      //     value: 1
      //   }],
      //   "key2": [{
      //     name: 'key3',
      //     value: 1
      //   }],
      //   "key3": []
      // }
    }

  },

  /**
   * 组件的初始数据
   */
  data: {
    typeList: [],
    count: 0,
  },
  lifetimes: {
    attached() {
      this.setData({
        list: this.data.list
      })
    },
  },
  observers: {
    list: function (val) {
      this.setData({
        typeList: Object.keys(val),
        count: keyArrLength(val)
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onRemove({
      currentTarget
    }) {
      const {
        dataset
      } = currentTarget
      const {
        key,
        value,
        subIndex
      } = dataset
      console.log(dataset, '-=--dataset--');
      const subList = this.data.list[key]
      subList.splice(subIndex, 1)

      this.setData({
        count: keyArrLength(this.data.list),
        list: Object.assign(this.data.list, {
          [key]: subList,
        })
      })



      this.triggerEvent('onRemove', {
        value: this.data.list
      })

      // const {curretn}
    },
    onVisibleChange(e) {
      console.log('--data---');


      // this.setData({
      //   visible: e.detail.visible,
      // });
    },
    // 收起
    onAway() {
      this.setData({
        visible: false
      })
    }
  }
})